package com.zbkj.admin.controller.platform;

import com.zbkj.common.annotation.LogControllerAnnotation;
import com.zbkj.common.enums.MethodType;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.*;
import com.zbkj.common.response.StoreClerkPageDataResponse;
import com.zbkj.common.response.StoreClerkRecordPageDataResponse;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.service.StoreClerkRecordService;
import com.zbkj.service.service.StoreClerkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 店小二管理 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/admin/platform/store/clerk")
@Api(tags = "店小二管理") //配合swagger使用

public class PlatformStoreClerkController {

    @Autowired
    private StoreClerkService storeClerkService;

    @Autowired
    private StoreClerkRecordService storeClerkRecordService;


    /**
     * 分页显示店小二设置表
     *
     * @param request          搜索条件
     * @param pageParamRequest 分页参数
     * @author dazongzi
     * @since 2025-06-27
     */
    //@PreAuthorize("hasAuthority('platform:activitystyle:list')")
    @ApiOperation(value = "分页列表") //配合swagger使用
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<StoreClerkPageDataResponse>> getList(@Validated StoreClerkSearchRequest request,
                                                                        @ModelAttribute PageParamRequest pageParamRequest) {
        CommonPage<StoreClerkPageDataResponse> storeClerkCommonPage = CommonPage.restPage(storeClerkService.getList(request, pageParamRequest));
        return CommonResult.success(storeClerkCommonPage);
    }

    /**
     * 新增店小二设置表
     * @param storeClerkSaveRequest 新增参数
     * @author dazongzi
     * @since 2025-06-27
     */
    @ApiOperation(value = "新增")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public CommonResult<String> save(@RequestBody @Validated StoreClerkSaveRequest storeClerkSaveRequest) {
        if(storeClerkService.create(storeClerkSaveRequest)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    @LogControllerAnnotation(intoDB = true, methodType = MethodType.DELETE, description = "批量删除店小二")
    @ApiOperation(value = "批量删除店小二")
    @RequestMapping(value = "/batch/delete", method = RequestMethod.POST)
    public CommonResult<String> batchDelete(@RequestBody @Validated CommonBatchRequest request) {
        if (storeClerkService.batchDelete(request.getIdList())) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    /**
     * 分页显示店小二记录表
     *
     * @param request          搜索条件
     * @param pageParamRequest 分页参数
     * @author dazongzi
     * @since 2025-06-27
     */
    //@PreAuthorize("hasAuthority('platform:activitystyle:list')")
    @ApiOperation(value = "分配记录列表") //配合swagger使用
    @RequestMapping(value = "/record/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<StoreClerkRecordPageDataResponse>> getRecordList(@Validated StoreClerkRecordSearchRequest request,
                                                                              @ModelAttribute PageParamRequest pageParamRequest) {
        CommonPage<StoreClerkRecordPageDataResponse> storeClerkRecordCommonPage = CommonPage.restPage(storeClerkRecordService.getList(request, pageParamRequest));
        return CommonResult.success(storeClerkRecordCommonPage);
    }

    @LogControllerAnnotation(intoDB = true, methodType = MethodType.DELETE, description = "批量删除店小二")
    @ApiOperation(value = "批量删除分配记录")
    @RequestMapping(value = "/record/batch/delete", method = RequestMethod.POST)
    public CommonResult<String> batchDeleteRecord(@RequestBody @Validated CommonBatchRequest request) {
        if (storeClerkRecordService.batchDelete(request.getIdList())) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

}



